package com.min.redis.common.util.bloom;

import java.util.BitSet;
import java.util.List;

public class BloomFilter<T> {

    int size;
    BitSet bitSet;
    
    List<HashFun<T>> hashFuns;
    
    public BloomFilter(int size,List<HashFun<T>> hashFuns){
        this.size = size;
        this.bitSet = new BitSet(size);
        this.hashFuns = hashFuns;
    }
    
        
    public void add(T t){
        for(HashFun<T> hashFun:hashFuns){
            bitSet.set(hashFun.hash(t)%size);
        }
    }

    public boolean contains(T t){
        for(HashFun<T> hashFun:hashFuns){
            if(!bitSet.get(hashFun.hash(t)%size)) return false;
        }
        return true;
    }

}
